

#ifndef __ExternalDevices_H_
#define __ExternalDevices_H_

#include "stm32h7xx.h"
#include "stm32_types.h"
#include "stm32h7xx_hal.h"

//tag 转盘步进电机方向   Turntable_Motor_direction_init
#define TURNTABLE_MOTOR_DIRECTION_INIT_GPIO_TYPEDEF		GPIOB
#define TURNTABLE_MOTOR_DIRECTION_INIT_GPIO_PIN			GPIO_PIN_3

//tag 转盘步进电机使能   Turntable_Motor_enable_init
#define  TURNTABLE_MOTOR_ENABLE_INIT_GPIO_TYPEDEF		GPIOB
#define  TURNTABLE_MOTOR_ENABLE_INIT_GPIO_PIN			GPIO_PIN_9	

//tag 零位检测端口配置 
#define ZERO_POSITION_DETECTION_GPIO_TYPEDEF	GPIOF
#define ZERO_POSITION_DETECTION_GPIO_PIN		GPIO_PIN_6

//tag 限位检测端口配置 
#define LIMIT_DETECTION_GPIO_TYPEDEF	GPIOE
#define LIMIT_DETECTION_GPIO_PIN		GPIO_PIN_8

//tag 启动开关端口配置 
#define START_SWITCH_GPIO_TYPEDEF	GPIOF
#define START_SWITCH_GPIO_PIN		GPIO_PIN_1

//tag 启动开关LED端口配置 
#define START_SWITCH_LED_GPIO_TYPEDEF	GPIOE
#define START_SWITCH_LED_GPIO_PIN		GPIO_PIN_3

//tag 打标机电源控制_端口配置
#define MARKING_MACHINE_POWER_GPIO_TYPEDEF		GPIOC
#define MARKING_MACHINE_POWER_GPIO_PIN			GPIO_PIN_11

//tag 打标机启停_端口配置
#define MARKING_MACHINE_START_AND_STOP_GPIO_TYPEDEF 	GPIOA
#define MARKING_MACHINE_START_AND_STOP_GPIO_PIN			GPIO_PIN_4

//tag 气缸位置1_电磁阀_端口配置
#define CYLINDER_POSITION_SOLENOID_VALVE_NO1_GPIO_TYPEDEF GPIOE
#define CYLINDER_POSITION_SOLENOID_VALVE_NO1_GPIO_PIN     GPIO_PIN_5

//tag 气缸位置2_电磁阀_端口配置
#define CYLINDER_POSITION_SOLENOID_VALVE_NO2_GPIO_TYPEDEF
#define CYLINDER_POSITION_SOLENOID_VALVE_NO2_GPIO_PIN

//tag 气缸位置3_电磁阀_端口配置
#define CYLINDER_POSITION_SOLENOID_VALVE_NO3_GPIO_TYPEDEF
#define CYLINDER_POSITION_SOLENOID_VALVE_NO3_GPIO_PIN

//tag 真空阀1 真空端口 端口配置
#define VACUUM_VALVE_NO1_PORT_GPIO_TYPEDEF		GPIOC
#define VACUUM_VALVE_NO1_PORT_GPIO_PIN			GPIO_PIN_11

//tag 真空阀1 破空端口 端口配置
#define VACUUM_VALVE_NO1_AIR_BREAKING_PORT_GPIO_TYPEDEF		GPIOC
#define VACUUM_VALVE_NO1_AIR_BREAKING_PORT_GPIO_PIN			GPIO_PIN_10

//tag 真空阀2 真空端口 端口配置
#define VACUUM_VALVE_NO2_PORT_GPIO_TYPEDEF		GPIOA
#define VACUUM_VALVE_NO2_PORT_GPIO_PIN			GPIO_PIN_10

//tag 真空阀2 破空端口 端口配置
#define VACUUM_VALVE_NO2_AIR_BREAKING_PORT_GPIO_TYPEDEF		GPIOA
#define VACUUM_VALVE_NO2_AIR_BREAKING_PORT_GPIO_PIN			GPIO_PIN_9

//tag 真空阀3 真空端口 端口配置
#define VACUUM_VALVE_NO3_PORT_GPIO_TYPEDEF		GPIOA
#define VACUUM_VALVE_NO3_PORT_GPIO_PIN			GPIO_PIN_8

//tag 真空阀3 破空端口 端口配置
#define VACUUM_VALVE_NO3_AIR_BREAKING_PORT_GPIO_TYPEDEF		GPIOA
#define VACUUM_VALVE_NO3_AIR_BREAKING_PORT_GPIO_PIN			GPIO_PIN_9

//tag 真空阀1 吸合 端口检测
#define VACUUM_VALVE_NO1_PULL_IN_DETECTION_GPIO_TYPEDEF	GPIOC
#define VACUUM_VALVE_NO1_PULL_IN_DETECTION_GPIO_PIN		GPIO_PIN_13

//tag 真空阀1 释放 端口检测
#define VACUUM_VALVE_NO1_RELEASE_DETECTION_GPIO_TYPEDEF	GPIOF
#define VACUUM_VALVE_NO1_RELEASE_DETECTION_GPIO_PIN		GPIO_PIN_2

//tag 真空阀2 吸合 端口检测
#define VACUUM_VALVE_NO2_PULL_IN_DETECTION_GPIO_TYPEDEF GPIOF
#define VACUUM_VALVE_NO2_PULL_IN_DETECTION_GPIO_PIN		GPIO_PIN_4

//tag 真空阀2 释放 端口检测
#define VACUUM_VALVE_NO2_RELEASE_DETECTION_GPIO_TYPEDEF	GPIOF
#define VACUUM_VALVE_NO2_RELEASE_DETECTION_GPIO_PIN		GPIO_PIN_6

//tag 真空阀3 吸合 端口检测
#define VACUUM_VALVE_NO3_PULL_IN_DETECTION_GPIO_TYPEDEF GPIOE
#define VACUUM_VALVE_NO3_PULL_IN_DETECTION_GPIO_PIN		GPIO_PIN_8

//tag 真空阀3 释放 端口检测
#define VACUUM_VALVE_NO3_RELEASE_DETECTION_GPIO_TYPEDEF	GPIOE
#define VACUUM_VALVE_NO3_RELEASE_DETECTION_GPIO_PIN		GPIO_PIN_6



// 定义枚举类型，表示真空阀的状态
typedef enum {
    VACUUM_ON,   // 抽真空（打开真空阀，关闭破空阀）
    VACUUM_OFF,  // 关闭真空阀
    VENT_ON,     // 破空（打开破空阀，关闭真空阀）
    VENT_OFF     // 关闭破空阀
} ValveState;



/// @brief 转盘电机方向初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Turntable_Motor_direction_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 转盘电机使能初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Turntable_Motor_enable_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);
/// @brief 转盘电机方向控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Turntable_Motor_direction_control(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);


/// @brief 转盘电机使能控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Turntable_Motor_enable_control(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);


/// @brief 零位检测_初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Zero_position_detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 限位检测_初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Limit_detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 读取_零为检测电平
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
extern GPIO_PinState Read_Zero_position_detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 读取_限位检测开关
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
extern GPIO_PinState Read_Limit_detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 启动开关_初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Start_switch_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 启动开关led初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Start_switch_led_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 启动开关LED 亮/灭
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Start_switch_led_setup(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

/// @brief 打标机电源控制 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Marking_machine_power_control_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 打标机电源控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Marking_machine_power_control(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

/// @brief 打标机启停 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Marking_machine_start_and_stop_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 打标机启停控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Marking_machine_start_and_stop(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

/// @brief 气缸位置1_电磁阀_初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Cylinder_position_solenoid_valve_no1_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 气缸位置2_电磁阀_初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Cylinder_position_solenoid_valve_no2_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 气缸位置3_电磁阀_初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Cylinder_position_solenoid_valve_no3_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 气缸位置电磁阀1控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Cylinder_position_solenoid_valve_no1_control(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

/// @brief 气缸位置电磁阀2控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Cylinder_position_solenoid_valve_no2_control(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

/// @brief 气缸位置电磁阀3控制
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param PinState 
extern void Cylinder_position_solenoid_valve_no3_control(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);

/// @brief 真空阀1 真空端口 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Vacuum_valve_no1_port_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀1 破空端口 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Vacuum_valve_no1_Air_breaking_port_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀2 真空端口 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Vacuum_valve_no2_port_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀2 破空端口 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Vacuum_valve_no2_Air_breaking_port_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀3 真空端口 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Vacuum_valve_no3_port_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀3 破空端口 初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void Vacuum_valve_no3_Air_breaking_port_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀_标号1_控制逻辑
/// @param state 
/// @param Vacuum_GPIOx 
/// @param Vacuum_GPIO_Pin 
/// @param Vacuum_PinState 
/// @param Breaking_air_GPIOx 
/// @param Breaking_air_GPIO_Pin 
/// @param Breaking_air_PinState 
extern void Vacuum_valve_no1_control(ValveState state , GPIO_TypeDef* Vacuum_GPIOx, uint16_t Vacuum_GPIO_Pin, GPIO_PinState Vacuum_PinState , 
                          GPIO_TypeDef* Breaking_air_GPIOx, uint16_t Breaking_air_GPIO_Pin, GPIO_PinState Breaking_air_PinState);

/// @brief 真空阀_标号2_控制逻辑
/// @param state 
/// @param Vacuum_GPIOx 
/// @param Vacuum_GPIO_Pin 
/// @param Vacuum_PinState 
/// @param Breaking_air_GPIOx 
/// @param Breaking_air_GPIO_Pin 
/// @param Breaking_air_PinState 
extern void Vacuum_valve_no2_control(ValveState state , GPIO_TypeDef* Vacuum_GPIOx, uint16_t Vacuum_GPIO_Pin, GPIO_PinState Vacuum_PinState , 
                          GPIO_TypeDef* Breaking_air_GPIOx, uint16_t Breaking_air_GPIO_Pin, GPIO_PinState Breaking_air_PinState);

/// @brief 真空阀_标号3_控制逻辑
/// @param state 
/// @param Vacuum_GPIOx 
/// @param Vacuum_GPIO_Pin 
/// @param Vacuum_PinState 
/// @param Breaking_air_GPIOx 
/// @param Breaking_air_GPIO_Pin 
/// @param Breaking_air_PinState 
extern void Vacuum_valve_no3_control(ValveState state , GPIO_TypeDef* Vacuum_GPIOx, uint16_t Vacuum_GPIO_Pin, GPIO_PinState Vacuum_PinState , 
                          GPIO_TypeDef* Breaking_air_GPIOx, uint16_t Breaking_air_GPIO_Pin, GPIO_PinState Breaking_air_PinState);						  

/// @brief 真空阀1 释放检测电平读取
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
GPIO_PinState Read_Vacuum_valve_no1_Pull_in_Detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 真空阀2 释放检测电平读取
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
GPIO_PinState Read_Vacuum_valve_no2_Pull_in_Detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 真空阀3 释放检测电平读取
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
GPIO_PinState Read_Vacuum_valve_no3_Pull_in_Detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 真空阀1 吸合检测电平读取
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
GPIO_PinState Read_Vacuum_valve_no1_Release_detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 真空阀2 吸合检测电平读取
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
GPIO_PinState Read_Vacuum_valve_no2_Release_detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 真空阀3 吸合检测电平读取
/// @param GPIOx 
/// @param GPIO_Pin 
/// @return 
GPIO_PinState Read_Vacuum_valve_no3_Release_detection(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/// @brief 真空阀3释放检测初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Spee 
void Vacuum_valve_no3_Release_detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Spee);

/// @brief 真空阀2释放检测初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Spee 
void Vacuum_valve_no2_Release_detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Spee);

/// @brief 真空阀1释放检测初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Spee 
void Vacuum_valve_no1_Release_detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Spee);

/// @brief 真空阀1吸合检测初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
void Vacuum_valve_no3_Pull_in_Detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀2吸合检测初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
void Vacuum_valve_no2_Pull_in_Detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);

/// @brief 真空阀3吸合检测初始化
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
void Vacuum_valve_no1_Pull_in_Detection_init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Mode, uint32_t Pull, uint32_t InitialState, uint32_t Speed);


/// @brief 二次映射GPIO端口配置
/// @param GPIOx 
/// @param GPIO_Pin 
/// @param Mode 
/// @param Pull 
/// @param InitialState 
/// @param Speed 
extern void ConfigureGPIO(GPIO_TypeDef* GPIOx, 
													uint16_t GPIO_Pin, 
													uint32_t Mode, 
													uint32_t Pull, 
													uint32_t InitialState, 
													uint32_t Speed);

#endif


